from nicegui import ui
from orm import manager
from tools import personalInspect
from tools.history_chart import History_chart
from tools.message import MessageSend


class User_page:
    def __init__(self, user_id) -> None:
        self.user = manager.get_user_byId(user_id)
        with ui.dialog() as self.dialog, ui.card().\
                tight().classes('w-[800px] h-[600px]'):
            with ui.card().classes('mx-auto w-full items-center'):
                with ui.row().classes('mx-auto'):
                    ui.image('/img/StarrySky_Logo.png').classes('w-[150px] h-[150px]')
                    with ui.column().classes('w-[150px] my-[8px]'):
                        with ui.row().classes('w-[140px]'):
                            ui.icon('account_circle', color='primary').classes('text-2xl my-auto')
                            ui.label(self.user.username).classes("text-2xl text-blue my-auto")
                        with ui.row().classes('w-[140px]'):
                            ui.icon('info', color='primary').classes('text-2xl my-auto')
                            ui.label(str(self.user.id)).classes("text-xl text-blue my-auto")
                        ui.button("发送私信",
                                  on_click=lambda: MessageSend(manager.get_user(self.user.username)),
                                  color='text-indigo-700', icon='receipt_long').classes(
                            'bg-gradient-to-br from-purple-200 to-blue-200 w-full')
            with ui.row().classes('w-full'):
                history = History_chart(self.user.id)
                history.create_accuracy_chart()
                history.create_amount()
            personalInspect.personalInspection(self.user.username)

    def open_page(self) -> None:
        self.dialog.open()
